package ca.ubc.icapture.genapha.forms;

import icapture.beans.DB.Gene;
import icapture.beans.DB.KeggPathway;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.util.TreeSet;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;
import org.apache.struts.validator.ValidatorForm;

/**
 * Form bean for Struts File Upload.
 */
public class GeneSnpForm extends ValidatorForm {

    private FormFile file;
    private int streamOffset = 0;
    private String filename;
    private String dlimiter;
    private boolean excel = false;
    private String submitType;
    private String database;
    private String useTextarea;
    private String textInput;
    private HashMap<String, ArrayList<ArrayList>> geneSnpHashMap;
    private Set<Gene> geneList;
    private HashMap<KeggPathway, TreeSet<Gene>> pathwayGeneMap;

    @Override
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        setSubmitType("");
        excel = false;
        useTextarea = "";
    }

    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = super.validate(mapping, request);

        if (getSubmitType().equalsIgnoreCase("Next")) {
            if (useTextarea == null || useTextarea.equals("")) {
                errors.add("geneSnp", new ActionMessage("geneSnp.error.noInputMethod"));
            } else {
                if (useTextarea.equals("file")) {
                    if (file.getFileSize() <= 0) {
                        errors.add("geneSnp", new ActionMessage("geneSnp.error.noFile"));
                    }
                } else if (useTextarea.equals("text")) {
                    if (textInput.equals("")) {
                        errors.add("geneSnp", new ActionMessage("geneSnp.error.noText"));
                    }
                }
            }
        }
        return errors;
    }

    /**
     * @return the file
     */
    public FormFile getFile() {
        return file;
    }

    /**
     * @param file the file to set
     */
    public void setFile(FormFile file) {
        this.file = file;
    }

    /**
     * @return the submitType
     */
    public String getSubmitType() {
        return submitType;
    }

    /**
     * @param submitType the submitType to set
     */
    public void setSubmitType(String submitType) {
        this.submitType = submitType;
    }

    public int getStreamOffset() {
        return streamOffset;
    }

    public void setStreamOffset(int offset) {
        streamOffset = offset;
    }

    public void setGeneSnpHash(HashMap<String, ArrayList<ArrayList>> snpHash) {
        geneSnpHashMap = snpHash;
    }

    public HashMap<String, ArrayList<ArrayList>> getGeneSnpHash() {
        return geneSnpHashMap;
    }

    public String getFilename() {
        return filename;
    }

    public void setFilename(String fn) {
        filename = fn;
    }

    public String getDlimiter() {
        return dlimiter;
    }

    public void setDlimiter(String dlimit) {
        dlimiter = dlimit;
    }

    public boolean getExcel() {
        return excel;
    }

    public void setExcel(boolean ex) {
        excel = ex;
    }

    public String getDatabase() {
        return database;
    }

    public void setDatabase(String db) {
        database = db;
    }

    /**
     * @return the geneList
     */
    public Set<Gene> getGeneList() {
        return geneList;
    }

    /**
     * @param geneList the geneList to set
     */
    public void setGeneList(Set<Gene> geneList) {
        this.geneList = geneList;
    }

    /**
     * @return the pathwayGeneMap
     */
    public HashMap<KeggPathway, TreeSet<Gene>> getPathwayGeneMap() {
        return pathwayGeneMap;
    }

    /**
     * @param pathwayGeneMap the pathwayGeneMap to set
     */
    public void setPathwayGeneMap(HashMap<KeggPathway, TreeSet<Gene>> pathwayGeneMap) {
        this.pathwayGeneMap = pathwayGeneMap;
    }

    public String getUseTextarea() {
        return useTextarea;
    }

    public void setUseTextarea(String use) {
        useTextarea = use;
    }

    public void setTextInput(String textInput) {
        this.textInput = textInput;
    }

    public String getTextInput() {
        return textInput;
    }
}
